#pragma once

#include "RHIRenderPass.h"

class RHIFrameBuffer : public RHIResource
{
	struct BuilderDetails {

		std::vector<RefCountPtr<RenderTarget>> renderTargets;

		RefCountPtr<RHIRenderPass> renderPass;

		uint32 count;

		uint32 width;

		uint32 height;

		uint32 layers;

		BuilderDetails();
	};

public:

	class Builder : public BuilderBase<BuilderDetails> {
		friend struct BuilderDetails;
	public:
		Builder() noexcept;
		Builder(Builder const& rhs) noexcept;
		Builder(Builder&& rhs) noexcept;
		~Builder() noexcept;
		Builder& operator=(Builder const& rhs) noexcept;
		Builder& operator=(Builder&& rhs) noexcept;

		Builder& AddRenderTarget(RefCountPtr<RenderTarget> renderTarget) noexcept;

		Builder& SetRenderPass(RefCountPtr<RHIRenderPass> renderPass) noexcept;

		Builder& SetCount(uint32 count) noexcept;

		Builder& SetWidth(uint32 width) noexcept;

		Builder& SetHeight(uint32 height) noexcept;

		Builder& SetLayers(uint32 layers) noexcept;

		RefCountPtr<RHIFrameBuffer> Build();
		RefCountPtr<RHIFrameBuffer> Build(RenderProcess* process, const std::string& name);

	private:
		friend class RHIFrameBuffer;
	};

	RHIFrameBuffer(BuilderDetails& builderDetails);

	virtual void ReleaseResource() override;

	virtual ~RHIFrameBuffer();

public:

	VkFramebuffer GetFrameBuffer(uint32 index = UINT32_MAX) const;

	VkRenderPassBeginInfo GetRenderPassBeginInfo(uint32 index = UINT32_MAX);

protected:

	std::vector<VkFramebuffer> mFrameBuffers;

	std::vector<VkClearValue> mClearValues;

	std::vector<std::vector<VkImageView>> mRenderTargetViewMap;

	VkRenderPassBeginInfo mRenderPassBeginInfo;

	uint32 mWidth;

	uint32 mHeight;

	uint32 mLayers;
};